package com.wtp.wallpaper.pojo.result;

import com.wtp.wallpaper.common.constant.MessageConstant;
import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {

    private Integer errCode;
    private String errMsg;
    private T data;

    public static <T> Result<T> success(){
        Result<T> result = new Result<T>();
        result.errCode = 0;
        result.errMsg = MessageConstant.QUERY_SUCCESS;
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.errCode = 0;
        result.errMsg = MessageConstant.QUERY_SUCCESS;
        result.data = data;
        return result;
    }

    public static <T> Result<T> error(String msg){
        Result<T> result = new Result<>();
        result.errMsg = msg;
        result.setErrCode(400);
        return result;
    }


}
